# 导包
import config
from api.login import LoginAPI
from common.assertutil import common_assert


# 创建测试类
class TestLoginAPI:
    # 前置处理
    def setup(self):
        # 实例化接口类
        self.login_api = LoginAPI()

    # 后置处理
    def teardown(self):
        pass

    # 登录成功（mobile和password正确）
    def test01_login_success(self):
        response = self.login_api.login(config.LOGIN_DATA)
        # # 断言响应状态码
        # assert 200 == response.status_code
        # # 断言success值
        # assert True == response.json().get("success")
        # # 断言code值
        # assert 10000 == response.json().get("code")
        # # 断言message包含指定值
        # assert "成功" in response.text
        common_assert(response)

    # 登录失败（mobile为空）
    def test02_without_mobile(self):
        response = self.login_api.login({"mobile": "", "password": "123456"})
        # # 断言响应状态码
        # assert 200 == response.status_code
        # # 断言success值
        # assert False == response.json().get("success")
        # # 断言code值
        # assert 20001 == response.json().get("code")
        # # 断言message包含指定值
        # assert "错误" in response.text
        common_assert(response, 200, False, 20001, "错误")

    # 登录失败（mobile未注册）
    def test03_mobile_not_exist(self):
        response = self.login_api.login({"mobile": "13800006677", "password": "123456"})
        # # 断言响应状态码
        # assert 200 == response.status_code
        # # 断言success值
        # assert False == response.json().get("success")
        # # 断言code值
        # assert 20001 == response.json().get("code")
        # # 断言message包含指定值
        # assert "错误" in response.text
        common_assert(response, 200, False, 20001, "错误")

    # 登录失败（password为空）
    def test04_without_password(self):
        response = self.login_api.login({"mobile": "13800000002", "password": ""})
        # # 断言响应状态码
        # assert 200 == response.status_code
        # # 断言success值
        # assert False == response.json().get("success")
        # # 断言code值
        # assert 20001 == response.json().get("code")
        # # 断言message包含指定值
        # assert "错误" in response.text
        common_assert(response, 200, False, 20001, "错误")

    # 登录失败（password与mobile不匹配）
    def test05_password_error(self):
        response = self.login_api.login({"mobile": "13800000002", "password": "667788"})
        # # 断言响应状态码
        # assert 200 == response.status_code
        # # 断言success值
        # assert False == response.json().get("success")
        # # 断言code值
        # assert 20001 == response.json().get("code")
        # # 断言message包含指定值
        # assert "错误" in response.text
        common_assert(response, 200, False, 20001, "错误")

